//
//  AffirmOrderCell.m
//  much
//
//  Created by weijunjie on 2019/1/10.
//  Copyright © 2019年 iOS. All rights reserved.
//

#import "AffirmOrderCell.h"
#import "GoodsModel.h"
#import "AffirmOrdeGoodsNumberView.h"

static NSString *AffirmOrderCellIdentifier = @"AffirmOrderCellIdentifier";
@interface AffirmOrderCell ()
/** 顶部线条  */
@property (nonatomic, strong) UIView *topLineView;
/** 商品图片 */
@property (nonatomic, strong) UIImageView *goodsImageView;
/** 商品描述 */
@property (nonatomic, strong) UILabel *titleLabel;
/** 商品规格 */
@property (nonatomic, strong) UILabel *standardLabel;
/** 商品规格数量 */
@property (nonatomic, strong) UILabel *standardNumberLabel;
/** 商品标签 */
@property (nonatomic, strong) UILabel *markLabel;
/** 售价 */
@property (nonatomic, strong) UILabel *priceLabel;
/** 划线价 */
@property (nonatomic, strong) UILabel *lineActionPriceLabel;
/** 市场均价 */
@property (nonatomic, strong) UILabel *singleBuyLabel;
/** 数量编辑内容视图 */
@property (nonatomic, strong) UIView *goodsNumerContentView;
@end
@implementation AffirmOrderCell

+ (instancetype)orderCellWithTableView:(UITableView *)tableView {
    AffirmOrderCell *cell = [tableView dequeueReusableCellWithIdentifier:AffirmOrderCellIdentifier];
    if (!cell) {
        cell = [[AffirmOrderCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:AffirmOrderCellIdentifier];
    }
    return cell;
}

- (void)setModel:(GoodsModel *)model {
    _model = model;
    [self.goodsImageView sd_setImageWithURL:[NSURL URLWithString:model.imagePath] placeholderImage:NewStoreDefault];
    self.titleLabel.text = model.title;
    self.standardLabel.text = model.name;
    self.priceLabel.text = [NSString stringWithFormat:@"¥%@",model.sellingPrice];
    self.lineActionPriceLabel.text = [NSString stringWithFormat:@"¥%@",model.marketSellingPrice];
    self.standardNumberLabel.text = [NSString stringWithFormat:@"x%ld",(long)model.number];
    
    self.goodsNumerView.model = model;
    self.goodsNumerContentView.hidden = NO;
}

#pragma mark - 懒加载
- (UIView *)topLineView {
    if (!_topLineView) {
        _topLineView = [[UIView alloc] init];
        _topLineView.backgroundColor = Color217;
        [self.contentView addSubview:_topLineView];
        [_topLineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).offset(15);
            make.top.right.equalTo(self.contentView);
            make.height.mas_equalTo(0.5);
        }];
    }
    return _topLineView;
}

- (UIImageView *)goodsImageView {
    if (!_goodsImageView) {
        _goodsImageView = [[UIImageView alloc] init];
        [_goodsImageView xw_roundedCornerWithCornerRadii:CGSizeMake(2, 2) cornerColor:[UIColor whiteColor] corners:UIRectCornerAllCorners borderColor:Color217 borderWidth:0.5];
        [self.contentView addSubview:_goodsImageView];
        [_goodsImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.topLineView).offset(12);
            make.left.equalTo(self.contentView).offset(15);
            make.width.height.mas_equalTo(76);
        }];
    }
    return _goodsImageView;
}

- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] init];
        [self.contentView addSubview:_titleLabel];
        _titleLabel.font = APPFONT(14);
        _titleLabel.textColor = Color34;
        _titleLabel.numberOfLines = 2;
        [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.goodsImageView);
            make.left.equalTo(self.goodsImageView.mas_right).offset(10);
            make.right.equalTo(self.contentView).offset(-15);
        }];
    }
    return _titleLabel;
}

- (UILabel *)standardLabel {
    if (!_standardLabel) {
        _standardLabel = [[UILabel alloc] init];
        [self.contentView addSubview:_standardLabel];
        _standardLabel.font = APPFONT(12);
        _standardLabel.textColor = Color140;
        _standardLabel.numberOfLines = 2;
        [_standardLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.titleLabel.mas_bottom);
            make.left.right.equalTo(self.titleLabel.mas_right);
        }];
    }
    return _standardLabel;
}

- (UILabel *)standardNumberLabel {
    if (!_standardNumberLabel) {
        _standardNumberLabel = [[UILabel alloc] init];
        [self.contentView addSubview:_standardNumberLabel];
        _standardNumberLabel.font = APPFONT(12);
        _standardNumberLabel.textColor = Color34;
        [_standardNumberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.priceLabel);
            make.right.equalTo(self.titleLabel);
        }];
    }
    return _standardNumberLabel;
}

- (UILabel *)markLabel {
    if (!_markLabel) {
        _markLabel = [[UILabel alloc] init];
        _markLabel.text = @"跨境";
        _markLabel.font = APPFONT(14);
        _markLabel.textAlignment = NSTextAlignmentCenter;
        _markLabel.backgroundColor = [UIColor clearColor];
        _markLabel.layer.borderWidth = 0.5;
        _markLabel.layer.cornerRadius = 2;
        _markLabel.layer.masksToBounds = YES;
        _markLabel.textColor = Color175030;
        _markLabel.layer.borderColor = Color175030.CGColor;
        [self.contentView addSubview:_markLabel];
    }
    return _markLabel;
}

- (UILabel *)priceLabel {
    if (!_priceLabel) {
        _priceLabel = [[UILabel alloc] init];
        _priceLabel.font = APPFONT(14);
        _priceLabel.textColor = Color175030;
        [self.contentView addSubview:_priceLabel];
        [_priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.titleLabel);
            make.top.equalTo(self.contentView).offset(78);
        }];
    }
    return _priceLabel;
}

- (UILabel *)lineActionPriceLabel {
    if (!_lineActionPriceLabel) {
        UIFont *font = APPFONT(12);
        UIColor *color = Color159;
        UILabel *singleBuyLabel = [[UILabel alloc] init];
        singleBuyLabel.font = font;
        singleBuyLabel.textColor = color;
        singleBuyLabel.text = @"市场均价";
        [self addSubview:singleBuyLabel];
        _singleBuyLabel = singleBuyLabel;
        [singleBuyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.priceLabel.mas_right).offset(5);
            make.centerY.equalTo(self.priceLabel);
        }];
        
        _lineActionPriceLabel = [[UILabel alloc] init];
        _lineActionPriceLabel.font = font;
        _lineActionPriceLabel.textColor = color;
        [self addSubview:_lineActionPriceLabel];
        [_lineActionPriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(singleBuyLabel.mas_right);
            make.centerY.equalTo(singleBuyLabel);
        }];
    }
    return _lineActionPriceLabel;
}

- (AffirmOrdeGoodsNumberView *)goodsNumerView {
    if (!_goodsNumerView) {
        
        UIView *goodsNumerContentView = [[UIView alloc] init];
        [self.contentView addSubview:goodsNumerContentView];
        [goodsNumerContentView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.equalTo(self.contentView);
            make.height.mas_equalTo(40);
        }];
        self.goodsNumerContentView = goodsNumerContentView;
        
        UILabel *titleLabel = [[UILabel alloc] init];
        titleLabel.text = @"购买数量:";
        titleLabel.font = APPFONT(15);
        titleLabel.textColor = Color34;
        [goodsNumerContentView addSubview:titleLabel];
        [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(goodsNumerContentView).offset(15);
            make.bottom.height.equalTo(goodsNumerContentView);
        }];
        
        
        _goodsNumerView = [[AffirmOrdeGoodsNumberView alloc] init];
        [goodsNumerContentView addSubview:_goodsNumerView];
        [_goodsNumerView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(goodsNumerContentView).offset(-15);
            make.bottom.equalTo(goodsNumerContentView).offset(-5);
            make.width.mas_equalTo(130);
            make.height.mas_equalTo(30);
        }];
    }
    return _goodsNumerView;
}

@end
